package emulator.unittest.hardware.nmos6502.commands;

import static org.junit.Assert.assertEquals;
import emulator.EmulatorException;
import emulator.hardware.HwByte;
import emulator.hardware.nmos6502.Command;
import emulator.hardware.nmos6502.Cpu6502;
import emulator.hardware.nmos6502.Flags6502;
import emulator.unittest.hardware.nmos6502.MockOperand;

public class CommandTestBase {

	protected Command command;

	public CommandTestBase() {
		super();
	}

	protected void executeAndCheckCommandOnAccu(Command command, int flags_pre,
			int accu_pre, int op, int flags_post, int accu_post)
			throws EmulatorException {
				MockOperand operand = new MockOperand(op);
				Cpu6502 cpu = new Cpu6502();
				cpu.setFlags(new Flags6502(flags_pre));
				cpu.setAccu(new HwByte(accu_pre));
				command.execute(cpu, operand);
				assertEquals(accu_post, cpu.getAccu().getNumber());
				assertEquals(new Flags6502(flags_post), cpu.getFlags());
			}

	protected void executeAndCheckCommandOnX(Command command, int flags_pre,
			int value_pre, int op, int flags_post, int value_post)
			throws EmulatorException {
				MockOperand operand = new MockOperand(op);
				Cpu6502 cpu = new Cpu6502();
				cpu.setFlags(new Flags6502(flags_pre));
				cpu.setX(new HwByte(value_pre));
				command.execute(cpu, operand);
				assertEquals(value_post, cpu.getX().getNumber());
				assertEquals(new Flags6502(flags_post), cpu.getFlags());
			}

	protected void executeAndCheckCommandOnY(Command command, int flags_pre,
			int value_pre, int op, int flags_post, int value_post)
			throws EmulatorException {
				MockOperand operand = new MockOperand(op);
				Cpu6502 cpu = new Cpu6502();
				cpu.setFlags(new Flags6502(flags_pre));
				cpu.setY(new HwByte(value_pre));
				command.execute(cpu, operand);
				assertEquals(value_post, cpu.getY().getNumber());
				assertEquals(new Flags6502(flags_post), cpu.getFlags());
			}

	protected void executeAndCheckCommandOnOperand(Command command, int flags_pre,
			int op_pre, int flags_post, int op_post)
			throws EmulatorException {
				MockOperand operand = new MockOperand(op_pre);
				Cpu6502 cpu = new Cpu6502();
				cpu.setFlags(new Flags6502(flags_pre));
				command.execute(cpu, operand);
				assertEquals(op_post, operand.getByte().getNumber());
				assertEquals(new Flags6502(flags_post), cpu.getFlags());
			}

}